<?php
defined('_JEXEC') or die;

/**
 * @package     Joomla.Administrator
 * @subpackage  com_content
 * @since       1.6
 */
class DoskaControllerMessage extends JControllerForm {
	
	public function __construct($config = array())
	{
		parent::__construct($config);

	}
	
	protected function allowAdd($data = array())
	{
		$user = JFactory::getUser();

		return ($user->authorise('core.create', $this->option.'.category.'.$data['id_categories']) || ($user->authorise('core.create.messages', $this->option.'.category.'.$data['id_categories'])));
	}
	
	
	protected function allowEdit($data = array(), $key = 'id')
	{
		
		$user = JFactory::getUser();
		$userId = $user->get('id');
		$messageId = (int)$data[$key] ? $data[$key] : 0;
		
		if($messageId) {
			
			if($user->authorise('core.edit','com_doska.message.'.$messageId)) {
				return TRUE;
			}
			
			if($user->authorise('core.edit.own','com_doska.message.'.$messageId)) {
				$message = $this->getModel()->getItem($messageId);
				
				if(empty($message)) {
					return FALSE;
				}
				
				$id = $message->id_user;
				
				if($userId == $id) {
					return TRUE;
				}
			}
			 
		}
		else {
			return parent::allowEdit($data,$key);
		}
	}

}